package codepulse.blogmoon.cn.system.controller;

import cn.dev33.satoken.stp.StpUtil;
import codepulse.blogmoon.cn.common.entity.Result;
import codepulse.blogmoon.cn.system.dto.LoginReq;
import codepulse.blogmoon.cn.system.dto.LoginResp;
import codepulse.blogmoon.cn.system.dubbo.AuthDubboService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/auth")
public class AuthController {

    @Resource
    private AuthDubboService authDubboService;

    @PostMapping("/login")
    public Result<String> login(@RequestBody LoginReq loginReq) {
        LoginResp loginResp = authDubboService.login(loginReq);
        return Result.success(loginResp.getToken());
    }

    @PostMapping("/logout")
    public Result logout() {
        StpUtil.logout();
        return Result.success();
    }


}
